<template>
  <div :class = "formDatas.isEdit?'field-item':''">
    <slot></slot>
    <div class = "field-action" v-if = "formDatas.isEdit">
      <i @click.stop = "selectData" title = "选中容器">
        <user-icon icon = "copy" style = "color:#e3e9f2;"/>
      </i>
      <i @click.stop = "removeData" title = "删除">
        <user-icon icon = "trash" style = "color:#e3e9f2;"/>
      </i>
    </div>
  </div>
</template>

<script>
import {confirm} from "../../../utils/message";

export default {
  name: "GroupBoxContainer",
  props: {
    formItem: {
      type: Object,
      required: true
    },
    formDatas: {type: Object, required: true}
  },
  data() {
    return {}
  },
  methods: {
    selectData() {
      let _this = this;
      this.$emit("selectItem", _this.formItem);
    },
    removeData() {
      let _this = this;
      confirm("删除容器，容器内的所有元素都会被删除", function (ok) {
        if (ok) {
          let dataList = _this.formDatas.dataList;
          let id = _this.formItem.preps.id;
          for (let i = 0; i < dataList.length; i++) {
            if (id === dataList[i].id) {
              dataList.splice(i, 1);
            }
          }
        }
      });
    }
  },
  watch: {
    'formItem.activeId': {
      deep: true,
      handler: function (v) {
      }
    }
  }
}
</script>

<style lang = "scss" scoped>

.field-item {
  margin-bottom: 5px;
  width: calc(100% - 10px);
  padding: 3px;

  .field-action {
    position: relative;
    bottom: 0;
    right: 15px;
    height: 22px;
    line-height: 22px;
    background: #3a8ee6;
    z-index: 9999999;
    float: right;
    width: 20px;
    text-align: right;
    display: flex;
    flex-direction: row;

    i {

      font-size: 14px;
      color: #fff;
      margin: 0 3px;
      cursor: pointer;
    }
  }

  .drag-handler {
    position: absolute;
    top: 0;
    left: -1px;
    height: 20px;
    line-height: 20px;
    background: #3a8ee6;
    z-index: 9;
    opacity: 0;

    i {
      font-size: 12px;
      font-style: normal;
      color: #409EFF;
      margin: 4px;
      cursor: move;
    }

    &:hover {
      opacity: 1;
      background: #3a8ee6;
    }
  }
}

.field-action, .drag-handler {
  .svg-icon {
    margin-left: 0;
    margin-right: 0;
  }
}

.el-form-item {
  position: relative;

  :deep(.el-form-item__label) {
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :deep(.el-form-item__content) {
    //position: unset;  /* TODO: 忘了这个样式设置是为了解决什么问题？？ */
  }

  span.custom-label i {
    margin: 0 3px;
  }

  :deep(.hide-spin-button) input::-webkit-outer-spin-button,
  :deep(.hide-spin-button) input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
  }

  :deep(.hide-spin-button) input[type="number"] {
    -moz-appearance: textfield;
  }
}

.required :deep(.el-form-item__label)::before {
  content: '*';
  color: #F56C6C;
  margin-right: 4px;
}

.static-content-item {
  min-height: 20px;
  display: flex; /* 垂直居中 */
  align-items: center; /* 垂直居中 */

  :deep(.el-divider--horizontal) {
    margin: 0;
  }
}

.el-form-item.selected, .static-content-item.selected {
  outline: 2px solid #1989fa;
}

:deep(.label-left-align) .el-form-item__label {
  text-align: left;
  justify-content: flex-start !important;
}

:deep(.label-center-align) .el-form-item__label {
  text-align: center;
  justify-content: center !important;
}

:deep(.label-right-align) .el-form-item__label {
  text-align: right;
  justify-content: flex-end !important;
}


</style>